package com.mall.mall.seckill.controller;

import com.mall.common.utils.R;
import com.mall.mall.seckill.service.SeckillService;
import com.mall.mall.seckill.to.SeckillSkuRedisTO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@RestController
public class SeckillController {

    @Autowired
    SeckillService seckillService;

    /**
     * 返回当前时间可以参于秒杀的商品信息
     * @return
     */
    @GetMapping("/currentSeckillSkus")
    public R getCurrentSeckillSkus(){
        List<SeckillSkuRedisTO> redisTOList = seckillService.getCurrentSeckillSkus();

        return R.ok().setData(redisTOList);
    }

    @GetMapping("/sku/seckill/{skuId}")
    public R getSkuSeckillInfo(@PathVariable("skuId") Long skuId){
        SeckillSkuRedisTO redisTO = seckillService.getSkuSeckillInfo(skuId);
        return R.ok().setData(redisTO);
    }

    @GetMapping("/kill")
    public R secKill(@RequestParam("killId") String killId, @RequestParam("key") String key, @RequestParam("num") Integer num){


        return null;
    }
}
